package org.dreamwork.cai.spring;

import org.dreamwork.cai.proxy.IServiceResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.stereotype.Service;

@Service
public class SpringServiceResolver implements IServiceResolver {
    private final DefaultListableBeanFactory factory;

    private String namespace;

    public SpringServiceResolver (@Autowired DefaultListableBeanFactory factory) {
        this.factory = factory;
    }

    public void setNamespace (String namespace) {
        this.namespace = namespace;
    }

    @Override
    public Object get (String name) {
        return factory.getBean (name);
    }

    @Override
    public <T> T get (Class<T> type) {
        return factory.getBean (type);
    }

    @Override
    public String getLocalNamespace () {
        return namespace;
    }
}